home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: malloc question
- Date: Tue, 12 Mar 96 00:04:40 GMT
- Organization: none
- Message-ID: <826589080snz@genesis.demon.co.uk>
- References: <4htonk$350@news.hklink.net> <4huctt$arv@sparcserver.lrz-muenchen.de> <314318AF.30F@iperbole.bologna.it> <4hvaj4$laj@solutions.solon.com> <AD69AACE9668D78B0@mcdiala09.it.luc.edu>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <AD69AACE9668D78B0@mcdiala09.it.luc.edu>
- VArase@varase.it.luc.edu "Verne Arase" writes:
-
- >In article <4hvaj4$laj@solutions.solon.com>,
- >seebs@solutions.solon.com (Peter Seebach) wrote:
- >
- > >>Error?!? Why do you think that casting is an error? The standard ANSI
- > >>runtime library says:
- > >
- > >He didn't say it was an error, he said it could *hide* an error.
- >
- >Well, in the general case it _could_ hide an error.
- >
- >In this specific case, however, it _never_ hides an error. If malloc is
- >used in its standard context, we are simply coercing a slab of memory
- >aligned to the most stringent boundaries into a pointer of the desired
- >type.
-
- It would hide an error if malloc was not previously declared (e.g. by
- including stdlib.h). Undeclared functions default to returning int so
- calling malloc like this results in undefined behaviour. Since it was not
- specific whether stdlib was included or not this is certainly a case where
- an error could be hidden.
-
- >Provided the associated header is included
-
- That's just it, you should never assume what isn't stated. This has been
- the cause of a problem too many times to ignore.
-
- >***** flame on ******
- >This is one reason I stopped participating in C conferences; there's always
- >some language lawyer who'll tell a novice that a cast is an evil (even if
- >it has to do with casting a char * to an unsigned char * for use in a file
- >name).
-
- Casts are not evil but they are dangerous and can be (and are) grossly
- misused especially by novices.
-
- >What they normally fail to tell you is that any code much beyond the
- >sophistication of "Hello World" practically requires casts to produce
- >workable code.
-
- They don't say this because it is simply isn't true, at least not with
- ANSI C. Casts are useful but you can write sophisticated code without using
- them. It takes experience to know which casts are safe and which are not.
- A beginner can easily get away without using them (particularly pointer
- casts) and will usually end up with better code when they do so.
-
- >IMO, making a char a signed quantity
-
- Whether char is signed or unsigned is implementation defined.
-
- >(along with the infamous misplacement
- >of the boolean and operator's priority) have made more C programmer's lives
- >miserable than any other construct in any other language (that I've
- >encountered).
-
- >Sure there are constructs that'll get you in trouble. But let us not forget
- >that C is the original "gun, bullet, foot" language, and requires care in
- >its use and execution.
-
- Which means that as a beginner you should avoid the more dangrous features
- of the language until you have a better understanding of it and the issues
- involved.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-